package org.creavi.engine.hud;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.creavi.engine.compiler.PrimitiveLoader;
import org.creavi.engine.resource.ResourceLocator;
import org.creavi.engine.util.StringRecord;

import com.jme.math.Vector2f;
import com.jme.util.export.Savable;

public class HudDefinitionLoader implements PrimitiveLoader {

	public String getBaseFolder() {
		return "hud";
	}

	public String getCompiledExtension() {
		return ResourceLocator.BINARY_HUD_EXTENSION;
	}

	public String getPrimitiveExtension() {
		return ResourceLocator.TEXT_HUD_EXTENSION;
	}

	public Savable loadResource(String name, InputStream is) throws IOException {
		HudDefinition hud = new HudDefinition();
		
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		
		String linea = br.readLine();

		StringRecord record = new StringRecord(linea);
		hud.setTextura(record.getString(0));
		hud.setUv1(new Vector2f(record.getFloat(1), record.getFloat(2)));
		hud.setUv2(new Vector2f(record.getFloat(3), record.getFloat(4)));
		hud.setScale(record.getFloat(5));
		
		return hud;
	}
	
}
